package cn.itsource.xhy.quartz.service.impl;

import cn.itsource.xhy.quartz.domain.QuartzJobInfo;
import cn.itsource.xhy.quartz.job.MainJob;
import cn.itsource.xhy.quartz.service.IQuartzService;
import cn.itsource.xhy.quartz.utils.QuartzUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

@Service
public class QuartzServiceImpl implements IQuartzService {

    @Autowired
    private SchedulerFactoryBean factoryBean;

    @Override
    public void addJob(QuartzJobInfo info) {

        QuartzUtils.addJob(factoryBean.getScheduler(),info.getJobName(), MainJob.class,info.getParams(),info.getCronj());
    }

    @Override
    public void removeJob(String jobName) {

        QuartzUtils.removeJob(factoryBean.getScheduler(),jobName);
    }
}
